package com.zhang.modules.video.controller;

import com.zhang.common.jpa.entity.DTO;
import com.zhang.common.jpa.entity.PageCmd;
import com.zhang.common.web.respWrapper.Res;
import com.zhang.modules.api.annotation.ApiPermission;
import com.zhang.modules.file.entity.cmd.CosFilePageCmd;
import com.zhang.modules.video.entity.VideoBasicInfo;
import com.zhang.modules.video.entity.cmd.VideoAddCmd;
import com.zhang.modules.video.entity.cmd.VideoEditCmd;
import com.zhang.modules.video.entity.cmd.VideoPageCmd;
import com.zhang.modules.video.service.IVideoBasicService;
import com.zhang.modules.video.service.impl.VideoBasicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Api(tags = "视频管理")
@RequestMapping("/api/bVideo")
@ApiPermission("sys:bVideo:*")
public class VideoBasicController {
    private IVideoBasicService service;

    public VideoBasicController(IVideoBasicService videoBasicService) {
        this.service = videoBasicService;
    }

    @ApiOperation("视频信息列表")
    @ApiPermission("sys:bVideo:page")
    @GetMapping("/page")
    public Res page(VideoPageCmd pageCmd, HttpServletRequest request){
        Page<DTO> result = service.page(VideoBasicInfo::new,pageCmd,request.getParameterMap());
        return Res.ok(result);
    }

    @ApiOperation("视频信息添加")
    @ApiPermission("sys:bVideo:add")
    @PostMapping("/add")
    public Res add(@RequestBody @Valid VideoAddCmd addCmd){
        service.save(addCmd,VideoBasicInfo::new);
        return Res.ok("添加成功");
    }


    @ApiOperation("视频信息删除")
    @ApiPermission("sys:bVideo:delete")
    @GetMapping("/delete")
    public Res delete(String id){
        service.delete(id);
        return Res.ok("删除成功");
    }

    @ApiOperation("视频信息编辑")
    @ApiPermission("sys:bVideo:edit")
    @PostMapping("/edit")
    public Res edit(@RequestBody @Valid VideoEditCmd editCmd){
        service.update(editCmd);
        return Res.ok("更新成功");
    }

    @ApiOperation("获取视频访问链接")
    @ApiPermission("sys:bVideo:url")
    @PostMapping("/url")
    private Res getUrl(String id){
        String videoUrl = service.getVideoUrl(id);
        return Res.ok(videoUrl);
    }


    @ApiOperation("获取视频详细详细")
    @ApiPermission("sys:bVideo:detail")
    @GetMapping("/detail")
    private Res detail(String id){
        VideoBasicInfo result = service.get(id);
        return Res.ok(result);
    }


}
